package com.woniuxy.caradmin.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.caradmin.entity.pojo.Outrecord;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.OutrecordService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.DataGridView;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author womenzu
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/outrecord")
public class OutrecordController {

    @Autowired
    private OutrecordService outrecordService;
    @GetMapping("/goOut")
    public ModelAndView  goOut(ModelAndView modelAndView){
        modelAndView.setViewName("out");
        return modelAndView;
    }
    @GetMapping("/goOutrecord")
    public ModelAndView  goOutrecord(ModelAndView modelAndView){
        modelAndView.setViewName("goOutrecord");
        return modelAndView;
    }
    @ApiOperation("显示所有的审核信息")
    @GetMapping("/outrecordList")
    public DataGridView outrecordList(){
        Page<Outrecord> page = PageHelper.startPage(1, 4);
        List<Outrecord> outrecords = outrecordService.selectOutcordList();
    if (outrecords!=null&&outrecords.size()>0){
        return new DataGridView(page.getTotal(), outrecords);
    } else {
        throw new CarException(ResultCode.APPLYNULL, Constaint.APPLYISNULL);
    }
    }
    @ApiOperation("增加审核信息")
    @GetMapping("/insertOut")
    public R insertOut(Outrecord outrecord){
        System.out.println(outrecord);
        Boolean result = outrecordService.insertOut(outrecord);
        if(result){
            return R.ok();
        }else {
            return R.error();
        }
    }
 }

